package com.com.datastructures.sort;

public class SS {
    static int a [] = new int[10];
    static int swapCount=0;
    static {
        int b [] = {3,6,2,13,9,5,1,8,12,14};
        a = b;
    }
    public static void main(String[] args){
        printData();
        selectionSort();
        printData();
    }
    //    static void selectionSort(){
//
//	for(int i=1;i<a.length;i++){
//	int j=i;
//	while( j>0 && (a[j-1]>a[j])){
//	int temp = a[j-1];
//	a[j-1] = a[j];
//	    a[j] = temp;
//	    j--;
//	}
//	}
//
//	}
    public static void selectionSort(){
        int min=0, outerIndex=0;
        for(int i=0;i<a.length-1;i++){
            min = i;
            for(int j=i+1; j<a.length; j++){
                if(a[min]>a[j]){
                    min=j;
                }
            }
            System.out.println(i+ "     " +min);
            swap(i,min);
        }
    }

    static void swap(int a1 ,int b1){
        swapCount++;
        int temp = a[a1];
        a[a1] = a[b1];
        a[b1] = temp;
    }

    static void printData(){
        System.out.print("\nItems: ");
        for(int i: a){
            System.out.print(i+" ");
        }
        System.out.println();
        System.out.println("Swap Count: "+swapCount);
    }
}
